package com.dream.keigezhushou.Activity.acty.listen;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.activity.BaseActivity;
import com.dream.keigezhushou.Activity.adapter.HotRecommendAdapter;
import com.dream.keigezhushou.Activity.pop.MoreWindow;
import com.dream.keigezhushou.Activity.pop.MoreWindowToMusicMessage;
import com.dream.keigezhushou.Activity.view.CircleImageView;
import com.dream.keigezhushou.Activity.wigdt.DividerItemDeoration;
import com.dream.keigezhushou.R;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HotRecommendActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rv_hot)
    RecyclerView rvHot;
    @BindView(R.id.ivBBAlbum)
    CircleImageView ivBBAlbum;
    @BindView(R.id.tvBBTitle)
    TextView tvBBTitle;
    @BindView(R.id.tvBBSinger)
    TextView tvBBSinger;
    @BindView(R.id.ib_Next)
    ImageView ibNext;
    @BindView(R.id.ib_Play_pause)
    ImageView ibPlayPause;
    @BindView(R.id.ib_previous)
    ImageView ibPrevious;
    @BindView(R.id.iv_more)
    ImageView ivMore;
    @BindView(R.id.rlBottomBar)
    RelativeLayout rlBottomBar;

    private ArrayList<String> h;
    private HotRecommendAdapter hotRecommendAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hot_recommend);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    //初始化界面
    protected void initView(){

        tvTitle.setText("热门推荐");

        h=new ArrayList<String>();
        for (int i = 'A'; i < 'L'; i++) {
            h.add("" + (char) i);
        }
    }

    //初始化数据
    protected void initData(){

        ivReturn.setOnClickListener(this);


        hotRecommendAdapter = new HotRecommendAdapter(this, h);
        rvHot.setAdapter(hotRecommendAdapter);
        rvHot.setLayoutManager(new LinearLayoutManager(this));
        //给recycleview划线
        rvHot.addItemDecoration(new DividerItemDeoration(this, DividerItemDeoration.VERTICAL_LIST));

        hotRecommendAdapter.addHeaderView(View.inflate(this,R.layout.golde30s_collecte_headerview,null));
        hotRecommendAdapter.setOnItemClickListener(new MyItemClickListener() {
            @Override
            public void onItemClick(int position) {

//                Toast.makeText(HotRecommendActivity.this,"Item开始调转页面了",Toast.LENGTH_SHORT).show();

//                    Intent intent =new Intent(HotRecommendActivity.this,HotMusicWordsActivity.class);
//                startActivity(intent);
//                Intent intent=new Intent(this,);

            }
            //more按钮出现popwindown
            @Override
            public void onBtnClick(int position) {
                final MoreWindow moreWindow = new MoreWindow(View.inflate(HotRecommendActivity.this, R.layout.golde30s_pupwindow, null), HotRecommendActivity.this, RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
                moreWindow.showPopAtLocation(rvHot, Gravity.BOTTOM);
                moreWindow.setItemListener(new MoreWindow.ItemClickListener() {
                    @Override
                    public void onClick() {
//                        Toast.makeText(HotRecommendActivity.this, "好样", Toast.LENGTH_SHORT).show();

                    }

                    @Override
                    public void onSingDetail() {


                        WindowManager wm = (WindowManager) HotRecommendActivity.this
                                .getSystemService(Context.WINDOW_SERVICE);

                        int width = wm.getDefaultDisplay().getWidth();
                        int height = wm.getDefaultDisplay().getHeight();


                        MoreWindowToMusicMessage moreWindowToMusicMessage = new MoreWindowToMusicMessage(View.inflate(HotRecommendActivity.this, R.layout.pop_musicmessage, null), HotRecommendActivity.this, width, ViewGroup.LayoutParams.WRAP_CONTENT);
//                       moreWindow.setBackColorState(0);
                        moreWindowToMusicMessage.showPopAtLocation(rvHot, Gravity.BOTTOM);
                        moreWindow.backGroundAlpha(0.4f);


                    }
                });
            }
        });

    }


    //点击事件的实现

    @Override
    public void onClick(View view) {

        switch (view.getId()){

            case R.id.iv_return:

                //返回
                finish();
                break;
        }
    }

    public interface MyItemClickListener {
        public void onItemClick(int position);

        public void onBtnClick(int position);
    }
}
